﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Confucius.dao;
using Confucius.daoImpl;
using Confucius.entity;
using System.Windows.Navigation;

namespace Confucius.pages
{
    /// <summary>
    /// Author:Liangchuan Gu
    /// date:2012-04-09
    /// </summary>
    public partial class NPCGreetingPage : PhoneApplicationPage
    {
        string greetingName = null;
        string greetingContent = null;
        string npcID = null;
        string iconID = null;
        string startDialogNodeID = null;

        public NPCGreetingPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (this.NavigationContext.QueryString.ContainsKey("name"))
            {
                greetingName = NavigationContext.QueryString["name"];
            }
            if (this.NavigationContext.QueryString.ContainsKey("greet"))
            {
                greetingContent = NavigationContext.QueryString["greet"];
            }
            if (this.NavigationContext.QueryString.ContainsKey("npcID"))
            {
                npcID = NavigationContext.QueryString["npcID"];
            }
            if (this.NavigationContext.QueryString.ContainsKey("iconID"))
            {
                iconID = NavigationContext.QueryString["iconID"];
            }
            if (this.NavigationContext.QueryString.ContainsKey("startDialogNodeID"))
            {
                startDialogNodeID = NavigationContext.QueryString["startDialogNodeID"];
            }

            PageName.Text = greetingName;
            Pagecontent.Text = greetingContent;

            // continue
        }
        
        private void talkMore_Click(object sender, RoutedEventArgs e)
        {
            NPCDAO npcDAO = new NPCDAOImpl();
		    String status = npcDAO.readNPCStatus(npcID);

            if(status.Equals(NPC.NOT_CHATTABLE)) 
            {
                MessageBox.Show("You cannot talk with this NPC. It seems you have to unlock something.",
                    "Notice", MessageBoxButton.OK);
			} 
            else 
            {
				if(status.Equals(NPC.END_CHAT))
                {
                    MessageBox.Show("You've finished a chat to uncover something. Go on to find something else.",
                    "Notice", MessageBoxButton.OK);	
				}
                string url = "/pages/NPCTalkingPage.xaml?npcID=" + npcID + "&startDialogNodeID=" + startDialogNodeID;
                Uri uri = new Uri(url, UriKind.Relative);
                NavigationService.Navigate(uri);
			}

            
        }

        private void goAway_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GoBack();
        }

    }
}